﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.DO;
using VINETLIFE.BL;
using System.Data;
using System.Web.UI.HtmlControls;

namespace VINETLIFE
{
    public partial class Category : System.Web.UI.Page
    {
        cmsCategoryDO objCategory;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                int categoryID = int.Parse(Request.QueryString["ID"]);
                LoadArticleByCategory(categoryID);
                ltrBreadcrumbs.Text = Ultility.Breadcrumb("category", categoryID);
                objCategory = new cmsCategoryBL().Select(new cmsCategoryDO() { CategoryID = categoryID });
                ltrCateName.Text = objCategory.Title;
                //SEO
                LoadSEO();
               
            }
            else 
            {
                Response.Redirect("/");
            }
        }
        protected void LoadSEO()
        {
            HtmlMeta metaKey = new HtmlMeta();
            metaKey.Name = "keywords";
            if (!string.IsNullOrEmpty(objCategory.MetaTag))
            {
                metaKey.Content = objCategory.MetaTag;
            }
            else
            {
                metaKey.Content = objCategory.Description;
            }
            Page.Header.Controls.Add(metaKey);
            //DESC
            HtmlMeta metaDesc = new HtmlMeta();
            metaDesc.Name = "description";
            if (!string.IsNullOrEmpty(objCategory.MetaDes))
            {
                metaDesc.Content = objCategory.MetaDes;
            }
            else
            {
                metaDesc.Content = objCategory.Description;
            }
            Page.Header.Controls.Add(metaDesc);

            if (!string.IsNullOrEmpty(objCategory.PageTitle))
            {
                Page.Title = objCategory.PageTitle;// +" | " + Ultility.WebTitle();
            }
            else
            {
                Page.Title = objCategory.Title;// +" | " + Ultility.WebTitle();
            }
        }
        private void LoadArticleByCategory(int categoryID)
        {
            CollectionPager1.MaxPages = 10000;

            CollectionPager1.PageSize = 28; // số items hiển thị trên một trang

            CollectionPager1.DataSource = new cmsArticleBL().SelectByCategoryX(categoryID).DefaultView;

            CollectionPager1.BindToControl = rptNews;
            rptNews.DataSource = CollectionPager1.DataSourcePaged;
            rptNews.DataBind();
        }
        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
        public string WordCut(string text)
        {
            return Ultility.WordCut(text, 260, new char[] { ' ', '.', ',', ';' }) + "...";
        }
    }
}